package com.adcc.monitoragent.show.receive;

import java.util.List;

import com.adcc.monitoragent.show.receive.impl.BroadcastReceive;
import com.adcc.monitoragent.show.service.ShowReceiveListener;
import com.adcc.monitoragent.util.ProtertiesUtil;

/**
 * 消息接收接口
 * @author charlie
 *
 */
public abstract class MessageReceive {
	private static MessageReceive recive = null;
	/**
	 * 初始化连接
	 * @param ip
	 * @param port
	 * @return
	 */
	public abstract boolean connect(int port);
	
	/**
	 * 初始化接收消息连接
	 * @param showClusterNames 监控集群名称
	 * @param port  监听端口
	 */
	public static void init(List<Object> showClusterNames, int port) {
		//初始化接收对象，可以接收任何改端口的udp信息
		BroadcastReceive temp = BroadcastReceive.getInstence();
		recive = temp;
		recive.connect(port);
		temp.addListener(new ShowReceiveListener(showClusterNames));
	}
	
	public static void init() {
		init(ProtertiesUtil.getShowClusterNames(), ProtertiesUtil.getRecivePort());
	}
}
